<html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    {block name="title"}<title>后台管理中心</title>{/block}
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8">
    <link rel="stylesheet" href="/vendor/layui-admin/layui/css/layui.css">
    <link rel="stylesheet" href="/vendor/layui-admin/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/vendor/layui-admin/css/admin.css">

<body class="layui-layout-admin">

<!--主视图-->
{block name="main"}{/block}

<script src="/vendor/layui/layui.js"></script>
<!-- <script src="/static/js/jquery-3.6.3.min.js"></script> -->
<!--<script src="/vendor/layui-admin/layui/layui.js"></script>-->

<!--操作标签-->
{block name="action"}
{/block}

{block name="footer"}
<script type="text/javascript">

    //js参数初始化 模块
    {block name="param"}{/block}

    layui.config({
        base: '/vendor/layui-admin/layui/modules/js/' //静态资源所在路径
    });

    //初始化表格字段
    function init_cols(cols){
        var arr = [];
        cols.forEach((val) => {
            if(val.type == 'button'){
                val.templet = function (d) {
                    var str = '';
                    d.LAY_COL.option.forEach((v) => {
                        if(v[0] == d[d.LAY_COL['field']]){
                            var color = 'layui-btn-primary';
                            if(v[2] == ''){
                                color = '';
                            }else if(v[2] != undefined){
                                color = 'layui-btn-'+v[2];
                            }
                            str = '<button type="button" class="layui-btn layui-btn-xs '+color+'">'+v[1]+'</button>';
                        }
                    })
                    return str;
                }
            }else if(val.type == 'img'){
                val.templet = function (d) {
                    var str = '';
                    d[d.LAY_COL['field']].split(',').forEach((elem, index) => {
                        if(elem != ''){
                            str += '<img style="padding-left: 10px;" src="'+elem+'" class="view_cp" width="auto" height="100%">';
                        }
                    });
                    return str;
                }
            }else if(val.type == 'time'){
                val.templet = function (d) {
                    if( d[d.LAY_COL['field']] ==0 ){
                        return '';
                    }
                    return new Date(parseInt(d[d.LAY_COL['field']]) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
                }
            }
            arr.push(val);
        });
        return cols;
    }

    layui.define(['table','form','admin','laydate'], function(exports) {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var table_filter = {};

        {block name="layui_table"}

            table.render({
                elem: '#table'
                , url: list_url
                , cols: [cols]
                ,limits: [15, 30, 50, 100, 200, 500, 1000]
                , page: true
                , limit: 20
                ,toolbar: true //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
                , height: 'full-180'
                , text: {
                    none: '无数据' //默认：无数据。
                }
            });
            //筛选框监听
            form.on('submit(search)', function(data){
                table_filter = data.field; //执行重载
                table.reload('table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        filter:table_filter
                    }
                });
                partition_id=data.field.partition_id
                return false;
            });
            //重载 刷新
            $('#layui-icon-refresh').click(function () {
                reload();
            });
            //重载 刷新
            function reload(){
                table.reload('table',{
                    where: {
                        filter:table_filter
                    }
                });
            }
            exports('level', {});
            $(document).on('click','.view_cp',function(){
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    shadeClose: true,
                    area: 'auto',
                    content: '<img style="display: inline-block;  height: 300px;" src="'+$(this).attr('src')+'">'
                });
            });
            //日期时间范围
            laydate.render({
                elem: '#time_start'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#time_end'
                ,type: 'datetime'
            });

        {/block}

        //编辑 删除
        table.on('tool(table)', function(obj){
            var data = obj.data;
            {block name="layui_event"}
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            url: del_url+'?id='+data.id
                            ,data: {"id":data.id,"status":0}
                            ,type: 'DELETE'
                            ,success(res){
                                if (res.code == 0){
                                    table.reload("table");
                                    layer.msg('删除成功');
                                } else{
                                    layer.msg('删除失败');
                                }
                            }
                        });
                        layer.close(index);
                    });
                }else if(obj.event === 'del_title'){
                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            url: del_url+'?title='+data.title
                            ,data: {"title":data.title}
                            ,type: 'DELETE'
                            ,success(res){
                                if (res.code == 0){
                                    table.reload("table");
                                    layer.msg('删除成功');
                                } else{
                                    layer.msg('删除失败');
                                }
                            }
                        });
                        layer.close(index);
                    });
                }else if(obj.event === 'update'){
                    layer.confirm('确认操作么', function(index){
                        $.ajax({
                            url: update_url
                            ,data: {"id":data.id}
                            ,type: 'POST'
                            ,success(res){
                                if (res.code == 0){
                                    table.reload("table");
                                    layer.msg('处理完成');
                                } else{
                                    layer.msg(res.msg);
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ["100%", "100%"],
                        content: edit_url+'?id='+data.id,
                        end: function () {
                            //更新表格
                            table.reload("table");
                            $("#layui-icon-refresh").click();
                        }
                    });
                } else if(obj.event === 'edit_title'){
                    layer.open({
                        type: 2,
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ["100%", "100%"],
                        content: update_url+'?title='+data.title,
                        end: function () {
                            //更新表格
                            $("#layui-icon-refresh").click();
                        }
                    });
                }else if(obj.event === 'get_tags_user'){
                    var data = obj.data;
                    $.ajax({
                        url: get_tags_user
                        ,data: {"tag_id":data.id}
                        ,type: 'POST'
                        ,success(res){
                            if (res.code == 0){
                                if(res.data == ''){
                                    layer.msg('该标签下暂时没有用户');
                                }else{
                                    layer.msg('该标签下的用户有 : '+res.data);
                                }
                            } else{
                                layer.msg('获取失败 请稍候重试');
                            }
                        }
                    });
                }else{
                    funcname = obj.event;
                    window[funcname](data)
                }
            {/block}
        });

        function curl(url,data,type){
            var result;
            $.ajax({
                url: url
                ,data: data
                ,type: type
                ,async:false
                ,success(res){
                    if(typeof  res == "string"){
                        res = JSON.parse(res);
                    }
                    result = res;
                }
            });
            return result;
        }

    });
    window.addEventListener('message', function(event) {
        if (event.data && event.data.type === 'openNewWindow') {
            window.open(event.data.url, '_blank');
        }
    });
</script>
{/block}

</body>
</html>